package mygang.model.constructor.field;

import java.io.Serializable;
import javax.persistence.*;
import mygang.helper.Utils;
import mygang.model.BaseModel;
import mygang.model.Option;
import mygang.model.OptionInterface;
import org.hibernate.annotations.Proxy;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 22/09/2012
 */
@Entity
@Table(name = "FIELD_TEMPLATE")
@Proxy(lazy = false)
public class FieldTemplate extends BaseModel implements Serializable, OptionInterface {

    @Id
    @Column(name = "FT_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="UIE_ID")
    private Element element;
    
    @Column(name = "FT_NAME")
    private String name;
    
    @Column(name = "FT_IS_ACTIVE")
    private boolean isActive;
    
    @Column(name = "FT_MASK")
    private String mask;
    
    @Column(name = "FT_REGEX")
    private String regex;
    
    
    public FieldTemplate() {
    }
    
    public FieldTemplate(long id, String name, Element element) {
        this(name, element);
        this.id = id;
    }
    
    public FieldTemplate(String name, Element element) {
        this.name = name;
        this.element = element;
    }
    
    public FieldTemplate(String name, Element element, String regex, String mask, boolean isActive) {
        this(name, element);
        this.regex = regex;
        this.mask = mask;
        this.isActive = isActive;
    }
    
    public FieldTemplate(long id, String name, Element element, String regex, String mask, boolean isActive) {
        this(name, element, regex, mask, isActive);
        this.id = id;
    }
    
    public FieldTemplate(long id) {
        this.id = id;
    }

    public Element getElement() {
        return element;
    }

    public void setElement(Element element) {
        this.element = element;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isActive() {
        return isActive;
    }
    
    public void setActive(boolean isActive) {
        this.isActive = isActive;
    }

    public String getMask() {
        return mask!=null ? mask : "";
    }

    public void setMask(String mask) {
        this.mask = mask;
    }

    public String getRegex() {
        return regex!=null ? regex : "";
    }

    public void setRegex(String regex) {
        this.regex = regex;
    }

    public Option toOption() {
        return new Option(Long.toString(getId()), getName());
    }
    
    @Override
    public String toString(){
        return Utils.toString(this);
    }
}